﻿

#region File Description

#endregion


#region Using Statements

// System References
using System;
using System.Collections.Generic;
using System.Linq;

// XNA References
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

// Freeform References
using Freeform.Framework;
using Freeform.Framework.Graphics;
using Freeform.Framework.Utility;
using Freeform.Framework.Input;
using Freeform.Framework.Menu;

// Internal References
using CardGame.Card;

#endregion


namespace CardGame.Menu
{
    public class MainMenu : World
    {

        #region Members

        public Entity Title { get; set; }

        public MenuItem_Text CardEditor, CardWorld, IsoWorld, IsoEditor, Exit;

        private Single VerticalPosition = 32f;
        private Single VerticalOffset = 9f;

        #endregion


        #region Initialisation

        public MainMenu()
        {
            // Make background invisible.
            BackgroundColour = new Color(Vector4.Zero);

            // Create title.
            Title = new Entity(this);
            Title.SpatialProperties.Position = new Vector2(51.2f, 15);
            Title.SpatialProperties.Size = new Vector2(50, 20);
            Title.Actor = new Actor_Text2D(Title, "Card Game", Game.Content.Load<SpriteFont>("Font/Basic"));
            (Title.Actor as Actor_Text2D).UseNaturalFontSize = true;
            (Title.Actor as Actor_Text2D).NaturalFontScaling = Vector2.One / 4f;
            Title.Actor.Depth = 0.25f;
            Title.Actor.ColourOverlay = Color.CornflowerBlue;

            // Create buttons.
            MakeItem(ref CardWorld, "Test Card World");
            MakeItem(ref CardEditor, "Run Card Editor");
            MakeItem(ref IsoWorld, "Test Adventure World");
            MakeItem(ref IsoEditor, "Run Tile Editor");
            MakeItem(ref Exit, "Exit");

            // Setup button clicked events.
            CardWorld.ItemClicked += delegate(Object Item, EventArgs Args)
            {
                List<Player> Players = new List<Player>();
                Players.Add(new Player("CHOBRO"));
                Players.Add(new Player("Friendly Bus"));
                new Board(Players);
                IsEnabled = false;
                Viewports[0].IsVisible = false;
            };
            CardEditor.ItemClicked += delegate(Object Item, EventArgs Args)
            {
                // Uncomment this code when there is a card editor to load.
                // When your world closes, call Game.MainMenu.IsEnabled = true; to bring back the Main Menu.
                //IsEnabled = false;
                //new CardEditor();
            };
            IsoWorld.ItemClicked += delegate(Object Item, EventArgs Args)
            {
                IsEnabled = false;
                new Adventure.AdventureWorld();
                Viewports[0].IsVisible = false;
            };
            IsoEditor.ItemClicked += delegate(Object Item, EventArgs Args)
            {
                IsEnabled = false;
                new Adventure.Editor.AdventureEditorWorld();
                Viewports[0].IsVisible = false;
            };
            Exit.ItemClicked += delegate(Object Item, EventArgs Args) { Game.Exit(); };

            // Setup viewport.
            Viewport2D View = new Viewport2D(this);
            View.Camera.SpatialProperties.Size = new Vector2(100, 75);
            View.Depth = 0.5f;

        }

        #endregion


        private void ItemHighlighted(Object Item, EventArgs Args)
        {
            MenuItem_Text Text = Item as MenuItem_Text;
            Text.Actor.ColourOverlay = Color.Red;
            Text.TextActor.NaturalFontScaling = Vector2.One / 7f;
        }

        private void ItemLeft(Object Item, EventArgs Args)
        {
            MenuItem_Text Text = Item as MenuItem_Text;
            Text.Actor.ColourOverlay = Color.White;
            Text.TextActor.NaturalFontScaling = Vector2.One / 9f;
        }

        private void MakeItem(ref MenuItem_Text Item, String Text)
        {
            Item = new MenuItem_Text(this, Text, "Font/Basic");
            Item.SpatialProperties.Position = new Vector2(51.2f, VerticalPosition);
            Item.TextActor.NaturalFontScaling = Vector2.One / 9f;
            Item.TextActor.ColourOverlay = Color.White;
            Item.ItemHighlighted += ItemHighlighted;
            Item.ItemLeft += ItemLeft;
            VerticalPosition += VerticalOffset;
        }
    }
}
